﻿//    Copyright 2010 SharpBoard Library authors
//
//    This file is part of SharpBoard Library.
//
//    SharpBoard Library is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    SharpBoard Library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with SharpBoard Library.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace SharpBoardLibrary
{
    public class ToolBarButtonCollection : Dictionary<string, ToolBarButton>
    {
        public XElement XElement
        {
            get
            {
                XElement element = new XElement("ToolBarButtons");
                foreach (var button in this.Values)
                {
                    element.Add(button.XElement);
                }
                return element;
            }
        }

        public ToolBarButtonCollection(XElement element)
        {
            var buttons = from button in element.Elements("Button")
                          select button;
            this.Clear();
            foreach (var button in buttons)
            {
                ToolBarButton btn = new ToolBarButton(button);
                this.Add(btn.Name, btn);
            }
        }

        public static ToolBarButtonCollection LoadFromXML(string path)
        {
            XElement doc = XElement.Load(path);
            ToolBarButtonCollection btns = new ToolBarButtonCollection(doc);
            return btns;
        }

        public void SaveToXML(string path)
        {
            XElement.Save(path);
        }

    }
}
